package org.restoran.controller.web;

import org.restoran.model.User;
import org.restoran.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 * User: ecaterina
 * Date: 19.11.13
 * Time: 8:45
 */

@Controller
public class UserController extends AbstractController {

    @Autowired
    UserRepository userRepository;

    @RequestMapping(value="/user", method = RequestMethod.OPTIONS)
    public @ResponseBody String getAllUsers() {

        Iterable<User> users = userRepository.findAll();
        ArrayList<String> names = new ArrayList<>();
        for(User user: users){
            names.add(user.getName());
        }
        return success(names.toString());
    }
}
